package com.eascs.tdriskcloud.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.eascs.tdriskcloud.controller.FraudApiInvoker;
import com.eascs.tdriskcloud.entity.FraudApiResponse;
import com.eascs.tdriskcloud.entity.TdHitsInformation;
import com.eascs.tdriskcloud.form.BaseInfoForm;
import com.eascs.tdriskcloud.service.CallTDService;
import com.eascs.tdriskcloud.service.HitInfoParsService;
import com.eascs.tdriskcloud.service.TDRiskCloudService;

@Service
public class CallTDServiceImpl implements CallTDService {

	@Inject
	TDRiskCloudService tdService;
	
	@Inject
	HitInfoParsService service;
	
	@Override
	public String saveTDApiInterface(BaseInfoForm entity) {
		Map<String, Object> params = new HashMap<String, Object>();
        params.put("partner_code", "YYTgroup");// 此处值填写您的合作方标识
        params.put("secret_key", "578052a0a1094412ac2882e6249b5abe");// 此处填写对应app密钥
        params.put("event_id", "Loan_web_20170524");// 此处填写策略集上的事件标识
        params.put("resp_detail_type","attribution");
        params.put("account_name",entity.getAccountName());
        params.put("id_number",entity.getIdNumber());
        params.put("account_mobile",entity.getAccountMobile());
        FraudApiResponse apiResp = new FraudApiInvoker().invoke(params);
        System.out.println(apiResp.getSuccess());
        System.out.println(apiResp.getReason_code());
        return tdService.saveOutPutApiInfo(apiResp, entity);
	}

	@Override
	public void saveHitsInfoInterface(String tdId) {
		String sequenceId = tdService.querySeqIdById(tdId);
		tdService.saveHitsInfo(tdId, sequenceId);
	}

	@Override
	public <T> List<List<T>> parsHistDataInterface(String tdId) {
		List<TdHitsInformation> entityList = service.queryHitsInfoByTdId(tdId);
		List<List<T>> data = new ArrayList<>();
		
		for(int i = 0; i < entityList.size(); i ++){
			List<T> tList = new ArrayList<>();
			tList = tdService.parsHistData(entityList.get(i));
			data.add(tList);
		}
		
		return data;
	}

}
